//
//  InterfaceResultModel.m
//  Jared_AFN_Cache
//
//  Created by Jared on 2017/1/23.
//  Copyright © 2017年 Jared. All rights reserved.
//

#import "InterfaceResultModel.h"
#import "Model.h"
#import "Lists.h"
#import "usrinfo.h"
#import "MJExtension.h"

#define nilOrJSONObjectForKey(JSON_, KEY_) [[JSON_ objectForKey:KEY_] isKindOfClass:[NSNull class]] ? nil : [JSON_ objectForKey:KEY_]
@implementation InterfaceResultModel
+ (id)paserResult:(NSArray *)jsonArray{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    for (NSDictionary *jsonDict in jsonArray) {
        Model *model = [[Model alloc] init];
        model.assetUrl = nilOrJSONObjectForKey(jsonDict, @"assetUrl");
        
        [dataArray addObject:model];
    }
    return dataArray;
}

+ (id)paserResultWithData:(NSDictionary *)jsonDict{
    Model *model = [[Model alloc] init];
//    model.assetUrl = nilOrJSONObjectForKey(jsonDict, @"assetUrl");
    return model;
}

+ (id)paserResultToModelWithData:(NSDictionary *)jsonDict{
    NSDictionary *dataArray = nilOrJSONObjectForKey(jsonDict, @"list");
//    NSLog(@"dataArray==dataArray==%@", dataArray);
//    for (NSDictionary *dict in dataArray) {
//        Lists *model = [[Lists alloc] init];
//        model.userinfo = nilOrJSONObjectForKey(dict, @"userinfo");
//        model.addtime_f = nilOrJSONObjectForKey(dict, @"addtime_f");
//        model.content = nilOrJSONObjectForKey(dict, @"content");
//        model.coverimg_wh = nilOrJSONObjectForKey(dict, @"coverimg_wh");
//        model.coverimg = nilOrJSONObjectForKey(dict, @"coverimg");
//        [modelArray addObject:model];
//    }
//    NSArray *modelArray = [Lists mj_objectArrayWithKeyValuesArray:dataArray];
    return dataArray;
}

- (id)paserResultToModelWithUserData:(NSArray *)jsonArray{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    for (NSDictionary *dict in dataArray) {
        usrinfo *model = [[usrinfo alloc] init];
        model.uid = [nilOrJSONObjectForKey(dict, @"uid") intValue];
        model.uname = nilOrJSONObjectForKey(dict, @"uname");
        model.icon = nilOrJSONObjectForKey(dict, @"icon");
        [dataArray addObject:model];
    }
    return dataArray;
}

@end
